package thread;

import lombok.SneakyThrows;

/**
 * @author ypz
 * @date 2021/9/30 17:10
 */
public class JoinTest extends Thread {
    public JoinTest(String name) {
        super(name);
    }

    @SneakyThrows
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+",i="+i);
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        Thread t1 = new JoinTest("thread1");
        t1.start();
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+",i="+i);
            if (i==5){
                /**
                 * 当调用join方法的线程执行完成后，main线程开始执行
                 */
                t1.join();
            }
        }

    }
}
